package com.ctshk.app.user.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.enums.appUser.CertificateTypeEnum;
import com.ctshk.common.model.TokenUser;
import com.ctshk.rpc.system.dto.MainDataRowFieldDataDTO;
import com.ctshk.rpc.system.service.IMainDataTableService;
import com.ctshk.rpc.user.dto.UserMainDataRowFieldDataDTO;
import com.ctshk.rpc.user.service.IPassengerCertificatesService;
import com.ctshk.rpc.user.service.IUserElasticsearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 *  证件资料前端控制器
 * </p>
 *
 * @author 李新科
 * @date 2021/5/17 17:06
 */
@Api(value="证件资料", tags="证件资料")
@RestController
@RequestMapping("/passengerCertificates")
public class PassengerCertificatesController extends AppBaseController {

    @DubboReference
    private IPassengerCertificatesService passengerCertificatesService;

    @DubboReference
    private IMainDataTableService mainDataTableService;

    @DubboReference
    private IUserElasticsearchService userElasticsearchService;

    @ApiOperation(value="删除证件资料", notes="删除证件资料")
    @OperationLogAnnotation(operModul = OperationLogModel.USER, operType = OperationLogType.DELETE, operTitle = "删除证件资料", operDesc = "删除证件资料")
    @PostMapping("/delete/{id}")
    public Result delete(@PathVariable @NotNull(message = "id不能为空")
                         @ApiParam(name="id",required = true) Long id) throws Exception{
        TokenUser currentUser = getCurrentUser();
        return passengerCertificatesService.delete(id,currentUser.getId());
    }

    @ApiOperation(value="获取证件类型数据", notes="获取证件类型数据")
    @RequestMapping(value = "/getCertificatesData",method = {RequestMethod.POST,RequestMethod.GET})
    public Result<List<MainDataRowFieldDataDTO>> getCertificatesData() throws Exception{
        List<MainDataRowFieldDataDTO> mainDataRowFieldDataDTOS = mainDataTableService.groupByDataField(1348475429155237889L, 1348477526361763842L);
        return Result.success(mainDataRowFieldDataDTOS);
    }

    @ApiOperation(value="根据产品type和id获取证件类型数据", notes="根据产品type和id获取证件类型数据")
    @OperationLogAnnotation(operModul = OperationLogModel.USER, operType = OperationLogType.QUERY, operTitle = "根据产品type和id获取证件类型数据", operDesc = "根据产品type和id获取证件类型数据")
    @GetMapping(value = "/getDataByTypeAndProductId/{type}/{productId}")
    public Result<List<CertificateTypeEnum>> getCertificatesDataByTypeAndProductId(@PathVariable @NotNull(message = "产品id不能为空") Long productId
            , @PathVariable @NotNull(message = "业务类型不能为空") Integer type) throws Exception{
        return userElasticsearchService.getCertificatesDataByTypeAndProductId(productId,type);
    }
}
